package cn.tedu.news.controller;

import cn.tedu.news.mapper.CategoryMapper;
import cn.tedu.news.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryMapper categoryMapper;

    @GetMapping("/category/list")
    public List<Category> list(){
        System.out.println("===list()===");
        List<Category> list = categoryMapper.list();
        return list;
    }

    /**
     * 创建新分类
     * @param category
     */
    @PostMapping("/category/insert")
    public void doCreate(@RequestBody Category category){
          categoryMapper.insert(category);
    }

    @DeleteMapping("/category/delete/{id}")
    public void doDeleteById(@PathVariable("id") Integer id){
        categoryMapper.deleteById(id);
    }
}
